package javabasic.threads.CreateThreadMethods;

/**
 * 通过实现Runnable接口创建子线程，主线程和子线程交替执行，无法获取子线程返回值
 */
public class Method02Runable {
    public static void main(String[] args) {
        Thread myThread = new Thread(new runnableTest());
        myThread.start();
        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName()+"====="+i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class runnableTest implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName()+"-----"+i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
